const formatter = {
    filterEmptyData: (data) => {
        return data;
        // return Object
        //     .keys(data)
        //     .filter(key => data[key] !== '' && data[key] != null)
        //     .reduce((result, key, index) => {
        //         result[key] = data[key];
        //         return result;
        //     }, {});
    },
    submit: {
        common: (data) => {
            return {
                ...formatter.filterEmptyData(data)
            }
        },
        OrgUnit: (data) => {
            const { group_address: groupAddress, detail_address: detailAddress } = data;
            return {
                ...formatter.filterEmptyData(data),
                group_address: groupAddress.join('-') + '-' + detailAddress
            }
        }
    },
    values: {
        common: (data) => {
            const {
                group_id: groupId,
                group_id_name: groupIdName,
                belong_group_id: belongGroupId,
                belong_group_id_name: belongGroupIdName,
                party_group_id: partyGroupId,
                party_group_id_name: partyGroupIdName
            } = data;
            return {
                ...data,
                group_id: groupIdName || groupId,
                belong_group_id: belongGroupIdName || belongGroupId,
                party_group_id: partyGroupIdName || partyGroupId
            };
        },
        OrgUnit: (data) => {
            const { group_address: groupAddress } = data;
            const [ province, city, district ] = groupAddress.split('-');
            return {
                ...data,
                group_address: [ province, city, district ]
            };
        },
        OrgParty: (data) => {
            const { belong_group_id: belongGroupId, belong_group_id_name: belongGroupIdName } = data;
            return {
                ...data,
                belong_group_id: belongGroupIdName || belongGroupId
            };
        },
        MemberRetire: (data) => {
            const { party_group_id: partyGroupId, party_group_id_name: partyGroupIdName } = data;
            return {
                ...data,
                party_group_id: partyGroupIdName || partyGroupId
            };
        }
    },
    view: {
        common: (data) => {
            const {
                department_name: departmentName,
                group_id: groupId,
                group_id_name: groupIdName,
                belong_group_id: belongGroupId,
                belong_group_id_name: belongGroupIdName,
                party_group_id: partyGroupId,
                party_group_id_name: partyGroupIdName
            } = data;
            return {
                ...data,
                department: departmentName,
                group_id: groupIdName || groupId,
                belong_group_id: belongGroupIdName || belongGroupId,
                party_group_id: partyGroupIdName || partyGroupId
            };
        },
        OrgUnit: (data) => {
            const { group_address: groupAddress } = data;
            return {
                ...data,
                group_address: groupAddress.replace(/[-]/g, '')
            };
        }
    }
};

export default formatter;
